//
//  ZJRecFirstStoryTableViewCell.m
//  BreadTravel
//
//  Created by 张健 on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ZJRecFirstStoryTableViewCell.h"
#import "ZJRecFirstStoryCollectionViewCell.h"
#import "StoryDetailViewController.h"
#import "ZJElementsModel.h"
@interface ZJRecFirstStoryTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,retain)UICollectionView *collectionView;

@end

@implementation ZJRecFirstStoryTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setView];
    }
    return self;
}

- (void)setView{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    //设置滚动方向
    //flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //设置每个item的大小
    flowLayout.itemSize = CGSizeMake(WIDTH/2-20, 190);
    //设置最小行间距
    flowLayout.minimumLineSpacing = 10;
    //设置最小列间距
    flowLayout.minimumInteritemSpacing = 1;
    //设置item与边界的距离  上左下右
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 15, 10, 15);
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 420) collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.92 alpha:1];;
    [self.contentView addSubview:self.collectionView];
    
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    //注册cell
    [self.collectionView registerClass:[ZJRecFirstStoryCollectionViewCell class] forCellWithReuseIdentifier:@"ZJRecFirstStoryCollectionViewCell"];

    
}

//设置显示item的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.array.count;
}
//每个item内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *ID = @"ZJRecFirstStoryCollectionViewCell";
    ZJRecFirstStoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    cell.tableModel = [self.array objectAtIndex:indexPath.row];
    
    return cell;
}
//点击cell触发的方法,跳转到故事详情
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ZJTableModel *tableModel = [self.array objectAtIndex:indexPath.row];
    NSString *string = tableModel.spot_id;
    [self.myDelegate delegateFunction:string];
    
}

@end
